import telnetlib

host = '10.1.1.1'
User = 'cisco'
Pwd = 'cisco'

tn = telnetlib.Telnet(host)
tn.read_until('username:')
tn.write(User+'\n')
tn.read_until('password:')
tn.write(Pwd+'\n')

tn.write('config t\n')
tn.write('interface loopback 1\n')
tn.write('ip address 1.1.1.1 255.255.255.255\n')
tn.write('no shutdown\n')
tn.write('end\n')
tn.write('show tech\n')
tn.read_eager()
tn.read_lazy
replay = tn.read_all()
print (replay)    #最后我们通过 Telnetlib 的 read_all() 方法将登陆 SW1 后执行命令的所有过程记录下来，然后通过 print tn.read_all() 将其打印出来，这样你就能清楚地看到 Python 对 SW1 做了些什么。注：read_all() 方法只在退出 Telnet 后才会生效，因此我们必须在其之前通过 
tn.write（「exit\n」） #退出 Telnet。



From Netmiko import ConnectHandler()
Sw2 =
{'device':'cisco_ios',
'ip':'10.1.1.1',
'username':'cisco',
'password':'cisco',
}
connect = ConnectHandler(**Sw2)
config_commands = ['interface loopback 1','ip address 1.1.1.1 255.255.255.255']
output = connect.send_config_set(config_commands)
print (output)
result = connect.send_command('show run interface loopback 1')
print (result)



---------------
import paramiko
import time

host = '10.1.1.1'
User = 'cisco'
Pwd = 'cisco'

ssh_client = paramiko.ssh_client()
ssh_client.set_miss_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname = ip ,username=username,password=Pwd)

commands = ssh_client.invoke_shell()
commands.send('configure terminal\n')
commands.send('interface loopbacek 1\n')
commands.send('ip address 1.1.1.1 255.255.255.255\n')
commands.send('end\n')

time.sleep(2)
output = commands.recv(65535)
print (output)